<?php

require ( "../includes/config.php" );
require ( "../includes/CGI.php" );
require ( "../includes/SQL.php" );

$cgi = new CGI ();
$sql = new SQL ( $DBusername, $DBpassword, $server, $database );

if ( ! $sql->isConnected () )
{
  die ( $DatabaseError );
}

require ( "includes/Auth.php" );
$auth = new Auth ( $cgi, $sql, $admin_table );
$auth->checkAuth ( "index.php" );

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>Criar Status do Im&oacute;vel</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
<table border="0" cellpadding="1" cellspacing="0" width="100%"> 
<tbody> 
<tr> 
<td bgcolor="#333333"> <?PHP include "header.php"; ?>
<table bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" width="100%"> 
<tbody> 
<tr> 
<td colspan="4"> 
<table width="100%" cellpadding="0" cellspacing="0"> 
<tr> 
<td align="left" valign="top" class="leftbg"> <?PHP include "leftmenu.php"; ?></td> 
<td valign="top"> 
<h2 align="left"><img src="images/spacer.gif" height="10" width="15" />Criar Status do Im&oacute;vel</h2> 
<table width="95%" align="center" cellpadding="0" cellspacing="1"> 
<tr> 
<td> 
<p> Voc&ecirc; tem os seguintes Status do Im&oacute;veis abaixo. Para adicionar um novo Statusra na lista abaixo, por favor, <a href="property_status_add.php">clique aqui</a>.</p></td> 
</tr> 
</table>
<br />
<?php 

  if ( $cgi->getValue ( "op" ) == "UpdatePropertyStatus" )
  {
    $sql->execute ( "UPDATE " . $propertystatus_table . " SET
        propertystatus=" .
          $sql->quote ( $cgi->getValue ( "propertystatus" ) ) . "
      WHERE
        id=" . $sql->quote ( $cgi->getValue ( "id" ) ) );

    ?>
<p align="center"><font color="red"> Status <strong>
<?php
      
    echo $cgi->htmlEncode ( $cgi->getValue ( "propertystatus" ) );
  
    ?>
</strong> foi criado com sucesso!</font></p>
<?php
  }
  else if ($cgi->getValue ( "op" )=="PropertyStatusDelete")
  {
    $sql->execute ( "DELETE FROM " . $propertystatus_table .
      " WHERE id=" . $sql->quote ( $cgi->getValue ( "id" ) ) );

    ?>
<p align="center"><font color="red"> O Status foi exclu&iacute;do com sucesso!</font></p>
<?php
  }

  {        
    $rows = $sql->execute ( "SELECT * FROM " . $propertystatus_table .
      " ORDER BY propertystatus ASC", SQL_RETURN_ASSOC );

    $num = sizeof ( $rows );

    if ( $num == 0 )
    {
      ?>
<br />
<br />
<p align="center"><font color="red"> N&atilde;o foi poss&iacute;vel encontrar nenhum Status</font></p>
<br />
<br />
<?php
    }
    else if ( $num > 0 )
    {
      ?>
<table width="90%" align="center" cellpadding="2" cellspacing="1" bgcolor="#F3F3F3">
<tr><td height="32" colspan="2" align="left" valign="middle" background="images/top-menubg.gif" class="leftbg"> <b>Criar Status do Im&oacute;vel</b></td>  
</tr>
<?php
        
      for ( $i = 0; $i < $num; ++$i )
      {
        $id = $rows [ $i ] [ "id" ];
        $propertystatus = $rows [ $i ] [ "propertystatus" ];
          
        ?>
<tr class="row3">
<td>
<table>
<tr>
<td>
<form method="post">
<input name="op" type="hidden" value="UpdatePropertyStatus" />
<input name="id" type="hidden" value="<?php echo $id; ?>" />
<input name="propertystatus" type="text" value="<?php
  echo $propertystatus; ?>" size="45" maxlength="100" />
<input value="Atualizar" type="submit" class="submit" />
</form></td>
<td><form method="post">
<input name="id" type="hidden" value="<?php
  echo $id; ?>" />
<input name="op" type="hidden" value="PropertyStatusDelete" />
<input value="Deletar" type="submit" class="submit" onclick="return confirm('Deseja excluir este Status?');" />
<?php
$location_result = mysql_query("SELECT * FROM $property_table WHERE propertystatus = '$id'" ); 
$TotalListings = mysql_numrows($location_result);
echo "($TotalListings listagens)";
?></form></td>
</tr>
</table></td>
</tr>
<?php
      }
    }
    
    if ( $num != 0 ) { ?>
</table>
<?php }
  }
  
?>
<br />
<table width="95%" align="center" cellpadding="0" cellspacing="1">
<tr>
<td>
<p>[<a href="property_status_add.php">Adicionar novo Status</a>]</p></td>
</tr>
</table>
<p>&nbsp;</p></td>
</tr> 
</table> </td> 
</tr> 
</tbody> 
</table> </td> 
</tr> 
</tbody> 
</table> <?PHP include "footer.php"; ?>
</body>
</html>
